﻿using SuperSocket.SocketBase;
using System;
using System.Text;
using SuperSocket.SocketBase.Protocol;
using Serilog;

namespace ParkService.Core
{
    public class SocketSession : AppSession<SocketSession>
    {
        readonly ILogger _logger = Serilog.Log.Logger;

        public string ip { get; set; }

        public override void Send(string message)
        {
            _logger.Information($"{this.SessionID} 发送消息:" + message);
            base.Send(message);
        }

        protected override void OnSessionStarted()
        {
            _logger.Information($"{this.SessionID} Session已启动 {this.RemoteEndPoint.Address}");
            this.ip = this.RemoteEndPoint.Address.ToString();
            base.OnSessionStarted();
            //this.RemoteEndPoint.Address.ToString()
        }

        protected override void OnInit()
        {
            this.Charset = Encoding.UTF8;
            base.OnInit();
        }

        protected override void HandleUnknownRequest(StringRequestInfo requestInfo)
        {
            _logger.Information("{this.SessionID} 遇到未知的请求:{0}", requestInfo.Body);
            base.HandleUnknownRequest(requestInfo);
            
        }
    }
}
